#include "../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>

MQ::QueueManager::ptr mqp;

class QueueTest : public testing::Environment
{
public:
    void SetUp() override
    {
        LOG(INFO, "测试环境初始化ing...\n");
        mqp = std::make_shared<MQ::QueueManager>("./data/meta.db");
    }

    void TearDown() override
    {
        LOG(INFO, "测试环境清理ing...\n");
        mqp->clear();
    }
};


TEST(QueueTest,insert_test)
{   
    std::unordered_map<std::string, std::string> args;
    mqp->declareQueue("MsgQueue1", true, false, false, args);
    mqp->declareQueue("MsgQueue2", true, false, false, args);
    mqp->declareQueue("MsgQueue3", true, false, false, args);
    mqp->declareQueue("MsgQueue4", true, false, false, args);
    mqp->declareQueue("MsgQueue5", true, false, false, args);
    ASSERT_EQ(mqp->size(), 5);
}


TEST(QueueTest,delete_test)
{
    mqp->deleteQueue("MsgQueue4");
    MQ::MsgQueue::ptr mp = mqp->selectQueue("MsgQueue4");
    ASSERT_EQ(mp.get(), nullptr);
    
}


TEST(QueueTest,select_test)
{
    ASSERT_EQ(mqp->exists("MsgQueue1"), true);
    ASSERT_EQ(mqp->exists("MsgQueue2"), true);
    ASSERT_EQ(mqp->exists("MsgQueue3"), true);
    ASSERT_EQ(mqp->exists("MsgQueue5"), true);
}


int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new QueueTest);
    RUN_ALL_TESTS();
    return 0;
}

